<template>
	<view  v-show="!loginShow" >
	<view  class="first" style="height:60vh; width:100%; border: 0px solid red;  display: flex;justify-content: center;align-items: center;" >
	<view  class="first" style=" display: block; width:100%; border: 0px solid red;" >
		<view  class="first" style="width:100%; border: 0px solid red; height:100px;" >
		<b>读心AI</b>
		</view>
		
		<view  class="first" style="width:100%; border: 0px solid red;" >
		<TnLoading show animation  color="#01beff" type="success" mode="flower"
		duration="1" time-function="ease-in-out" size="100px" />
		</view>
	</view>
	</view>
	</view>
	
	<view  v-show="loginShow" >
	<view  v-show="false" style="border: 0px solid red; width:100%; height:100vh; display: flex;justify-content: center; align-items: center; " >
	
	<view  style="border: 0px solid blue; width:100%; height:350px;  " >
	
	<view  style="border: 0px solid red; width:100%; height:30%;  display: flex;justify-content: center; align-items: center;" >
	 <image style="width:100px; height:100px;" :src="avatarUrl" ></image>
	</view>
	<view  style="border: 0px solid red; width:100%; height:10%;  display: flex;justify-content: center; align-items: flex-start;" >
	 <TnButton height="30px"  width="100px" open-type="chooseAvatar" @chooseavatar="tChooseAvatar"  >获取登录头像</TnButton>
	</view>
	

	<view  style="border: 0px solid red; width:100%; height:20%;  display: flex;justify-content: center; align-items: center;" >
	<input type="nickname" id="tnickname"  @blur="handleInput"
	v-model="nickname"  placeholder="请点击获取或输入昵称"/>
	</view>
	

	
	<view  style="border: 0px solid red; width:100%; height:20%;  display: flex;justify-content: center; align-items: center;" >
	<TnButton height="30px"  width="200px" open-type="getPhoneNumber" 
	  @getphonenumber="gettPhoneNumber"  > 登录 </TnButton>
	</view>
	

	</view>
	
	
	</view>
	</view>
	
</template>

<script lang="ts" setup>
import { onLoad } from '@dcloudio/uni-app';
import TnButton  from '@/uni_modules/tuniaoui-vue3/components/button/src/button.vue'
import TnLoading from '@/uni_modules/tuniaoui-vue3/components/loading/src/loading.vue'
import { weixinlogin, userlogin, userApplogin } from '@/api/login'
import { setTokenRefCode } from '@/utils/auth'
import { ref, reactive, getCurrentInstance  } from 'vue'

const avatarUrl = ref('/static/head.png')
const nickname  = ref('')
const refcode   = ref("")
const loginShow = ref(false)



onLoad((options) => {
console.log( "===========onLoad=============start" )
console.log('1 页面 refcode : ', options.refcode );	
	uni.login({
		"provider": "weixin",
		success: function(res){
			console.log('-------loginRes----')
			console.log( res )

			// 获取用户信息
			uni.getUserInfo({
				provider: 'weixin',
				success: function (infoRes) {
					console.log('用户昵称为：' + infoRes.userInfo.nickName);
					console.log( infoRes )
					const deviceId = uni.getSystemInfoSync().deviceId;
					const data = { unionid: res.authResult.unionid,
								   openid: res.authResult.openid,
								   accessToken: res.authResult.access_token,
								   nickName: infoRes.userInfo.nickName,
								headerImage: infoRes.userInfo.avatarUrl,
								deviceid: deviceId,
								refcode:  options.refcode,
					}
					console.log( data )
					userApplogin( data, loginShow )
					console.log( "===========onLoad=============success" )



					
					
					
				},
				fail: function (error) {
					console.log( "===========onLoad=============error" )
					console.log( error )
				}
			})
		}
	})
})
		




</script>

<style>

.first{
	border: 1px solid red;
	height: 100px; 		/* 使用100%的高度来覆盖整个屏幕 */
	width:100%;
	/* 使用100%的高度来覆盖整个屏幕 */
	display: flex;
	justify-content: center;
	align-items: center;
}


</style>
